package com.example.javademo.util;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.TemplateConfig;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.util.Collections;

/**
 * @Description :
 * @Author 北风
 * @Date Created in 2021/10/14 13:59
 */
public class MybatisGenerator {

    public static void main(String[] args) {
        FastAutoGenerator.create("jdbc:mysql://1.15.155.253:3306/vhr", "ww", "wwAdmin8")
                .globalConfig(builder -> {
                    builder.author("北风") // 设置作者
                            .fileOverride() // 覆盖已生成文件
                            .outputDir(System.getProperty("user.dir") + "/src/main/java") // 指定输出目录
                            .disableOpenDir()
                            .fileOverride();
                })
                .packageConfig(builder -> {
                    builder.parent("com.example.demo"); // 设置父包名
                })
                .strategyConfig(builder -> {
                    builder.addInclude("middle_covid19_seq_simple") // 设置需要生成的表名
                            .entityBuilder()
                            .enableLombok()

                            .mapperBuilder()
                            .enableMapperAnnotation()
                            .enableBaseResultMap()
                            .enableBaseColumnList();
                })
                .templateConfig(builder -> {
                    builder.entity("/templates/entity.java")
                            .mapper("/templates/mapper.java")
                            .controller("/templates/controller.java")
                            .build();
                })
                .templateEngine(new FreemarkerTemplateEngine())
                .execute();

    }
}
